package com.smz.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.smz.dao.TMenuDAO;
import com.smz.entity.TMenu;
import com.smz.service.TMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TMenuServiceImpl extends ServiceImpl<TMenuDAO, TMenu> implements TMenuService {

    @Autowired
    private TMenuService tMenuService;
    @Autowired
    private TMenuDAO tMenuDao;


    @Override
    public Page<TMenu> findPageTMenus(Integer current, Integer rows,Integer tMenuId,String dateTime) {
        long count = tMenuService.count();
        Page<TMenu> page=new Page<>(current,rows,count);
        if (tMenuId==null && dateTime==null){
            Page<TMenu> data = tMenuService.page(page, null);
            return data;
        }else {
            if (tMenuId!=0&&dateTime!=null){
                Page<TMenu> data = tMenuService.page(page, new QueryWrapper<TMenu>().lambda().eq(TMenu::getId,tMenuId).likeRight(TMenu::getDeteTime,dateTime));
                return data;
            }else if (tMenuId!=0&&dateTime==null){
                Page<TMenu> data = tMenuService.page(page, new QueryWrapper<TMenu>().lambda().eq(TMenu::getId,tMenuId));
                return data;
            }else if (tMenuId==0&&dateTime!=null){
                Page<TMenu> data = tMenuService.page(page, new QueryWrapper<TMenu>().lambda().likeRight(TMenu::getDeteTime,dateTime));
                return data;
            }
        }
        return null;
    }

    @Override
    public Page<TMenu> findPageTMenu(Integer current, Integer rows,Integer tMenuId,java.sql.Timestamp dateTime) {
        long count = tMenuService.count();
        Page<TMenu> page=new Page<>(current,rows,count);
        if (tMenuId==null && dateTime==null){
            Page<TMenu> data = tMenuService.page(page, null);
            return data;
        }else {
            if (tMenuId!=0&&dateTime!=null){
                Page<TMenu> data = tMenuService.page(page, new QueryWrapper<TMenu>().lambda().eq(TMenu::getId,tMenuId).like(TMenu::getDeteTime,dateTime));
                return data;
            }else if (tMenuId!=0&&dateTime==null){
                Page<TMenu> data = tMenuService.page(page, new QueryWrapper<TMenu>().lambda().eq(TMenu::getId,tMenuId));
                return data;
            }else if (tMenuId==0&&dateTime!=null){
                Page<TMenu> data = tMenuService.page(page, new QueryWrapper<TMenu>().lambda().like(TMenu::getDeteTime,dateTime));
                return data;
            }
        }
        return null;
    }
    @Override
    public TMenu selectMenuById(Integer id) {
        return tMenuDao.selectMenuById(id);
    }

    @Override
    public List<TMenu> findAllTMenu() {
        return tMenuDao.selectAllTMenu();
    }
    @Override
    public List<TMenu> findAllMenu() {
        return tMenuDao.selectAllMenu();
    }
}
